import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;

public class ZookeeperConnect implements Watcher {
    public static final Integer TIMEOUT = 5000;
    public static final String SERVER_PATH = "127.0.0.1:2181";

    public static void main(String[] args) throws IOException, InterruptedException {
        ZooKeeper zooKeeper = new ZooKeeper(SERVER_PATH,TIMEOUT,new ZookeeperConnect());
        System.out.println("开始连接zookeeper服务器……");
        System.out.println(zooKeeper.getState());
        Thread.sleep(2000);
        System.out.println(zooKeeper.getState());
    }
    @Override
    public void process(WatchedEvent watchedEvent) {
        System.out.println("收到了通知……"+watchedEvent);
    }
}
